//  配置基地址
import {
  baseUrl
} from '../config/network'
import localStorage from '../utils/localStorage'
function request({
  url = '',
  method = 'GET',
  auth = true,
  header = {
    "content-type": "application/json",
    "token": localStorage.get('Authorization')
  },
  data = {}
}) {
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      method,
      data,
      header,
      timeout: 50000,
      //  成功回调
      success: res => {
        const {
          statusCode,
          data
        } = res;
        if (statusCode == 200) {
          resolve(data)
        } else {
          wx.showToast({
            title: '系统错误',
            icon: 'none'
          })
          reject(res)
        }
      },
      //  错误回调
      fail: err => {
        wx.showToast({
          title: '系统错误',
          icon: 'none'
        })
        reject(err)
      },
      //  请求完成回调
      complete: () => {}
    });
  })
}

//导出请求
export default request